function trim (myString)     
{     
    return myString.replace(/^\s+|\s+$/g, "");   
}

function change_order(type,orderby)
{
	if(orderby=="asc")
	{
		orderby="desc";
	}
	else
	{
		orderby="asc";
	}
	document.getElementById("type_title").value=type;
	document.getElementById("order_by").value=orderby;
	document.mainform.submit();
}

function check_all(totalrows)
{
	var status=false;
	if(document.getElementById("checkAll").checked)
	{
		status=true;
	}
		
	for(var i=1;i<=totalrows;i++)
	{
		document.getElementById("check_"+i).checked=status;
	}
	
	
}

function getdata(pid)
{
	document.getElementById("pid").value = pid;
	document.mainform.submit();
}

function getempfilterresults()
{
	if(trim(document.getElementById('filterby').value)=="")
	{
		alertify.alert("Please select filterby option.");
		document.getElementById("filterby").focus();
		return false;
	}
	else if(trim(document.getElementById('searchText').value)=="")
	{
		alertify.alert("Please enter search value.");
		document.getElementById("searchText").focus();
		return false;
	}
	else if(trim(document.getElementById('searchText').value)!="")
	{
		document.mainform.submit();
	}
}

function performoperation(stmsg,status,recid,fieldid)
{
	alertify.confirm("Are you sure, you want to "+stmsg+"?", function (e) {
		if (e) {
			alertify.success("You've clicked OK");
			document.getElementById(fieldid).value=recid;
			document.getElementById('opt_status').value=status;
			document.mainform.submit();
		} else {
			alertify.error("You've clicked Cancel");
		}
	});
	return false;
	
}

function editrecord(editid,fieldid,pagename)
{
	document.getElementById(fieldid).value=editid;
	document.mainform.action=pagename;
	document.mainform.submit();
}

function toggle_div(divname,imgid)
{
	$('#'+divname).toggle('slow', function() {
    
	});
	var imagearr=document.getElementById(imgid).src;
	imagearr=imagearr.split("images/")
	if(imagearr[1]=="desc.gif")
	{
		document.getElementById(imgid).src=imagearr[0]+"images/asc.gif";
	}
	else
	{
		document.getElementById(imgid).src=imagearr[0]+"images/desc.gif";
	}
}
function isNumberKey(evt)
{
	 var charCode = (evt.which) ? evt.which : event.keyCode
	 if (charCode > 31 && (charCode < 48 || charCode > 57))
	    return false;
	
	 return true;
}

// validation function for vendor add edit page
function validateaddeditvendor()
{
	
	if(trim(document.getElementById("fullname").value)=="")
	{
		alertify.alert("Please enter vendor full name!");
		document.getElementById("fullname").focus();
		return false;
	}
	else if(trim(document.getElementById("mwcid").value)=="")
	{
		alertify.alert("Please enter Mahindra world city identification card number!");
		document.getElementById("mwcid").focus();
		return false;
	}
	else if(trim(document.getElementById("contactno").value)=="")
	{
		alertify.alert("Please enter contact number!");
		document.getElementById("contactno").focus();
		return false;
	}
	else if(trim(document.getElementById("address").value)=="")
	{
		alertify.alert("Please enter address!");
		document.getElementById("address").focus();
		return false;
	}
	else if(trim(document.getElementById("area").value)=="")
	{
		alertify.alert("Please enter area!");
		document.getElementById("area").focus();
		return false;
	}
	else if(trim(document.getElementById("city").value)=="")
	{
		alertify.alert("Please enter city!");
		document.getElementById("city").focus();
		return false;
	}
	else if(trim(document.getElementById("state").value)=="")
	{
		alertify.alert("Please enter state!");
		document.getElementById("state").focus();
		return false;
	}
}

//validation function for add edit cab page
function validateaddeditvehicle()
{
	if(trim(document.getElementById("vendorid").value)=="0")
	{
		alertify.alert("Please select vendor!");
		document.getElementById("vendorid").focus();
		return false;
	}
	else if(trim(document.getElementById("vehiclenumber").value)=="")
	{
		alertify.alert("Please enter vehicle registered number!");
		document.getElementById("vehiclenumber").focus();
		return false;
	}
	else if(trim(document.getElementById("ownername").value)=="")
	{
		alertify.alert("Please enter cab owner name(driver name optional)!");
		document.getElementById("ownername").focus();
		return false;
	}
	else if(trim(document.getElementById("contactno").value)=="")
	{
		alertify.alert("Please enter contact number!");
		document.getElementById("contactno").focus();
		return false;
	}
	else if(trim(document.getElementById("driverid").value)=="0")
	{
		alertify.alert("Please select driver!");
		document.getElementById("driverid").focus();
		return false;
	}
	else if(trim(document.getElementById("max_capacity").value)=="")
	{
		alertify.alert("Please enter the allowed maximum cab seats!");
		document.getElementById("max_capacity").focus();
		return false;
	}
	else if(trim(document.getElementById("area").value)=="")
	{
		alertify.alert("Please enter the area of the cab!");
		document.getElementById("area").focus();
		return false;
	}
}

function validateaddeditdriver()
{
	if(trim(document.getElementById("fullname").value)=="")
	{
		alertify.alert("Please enter driver full name!");
		document.getElementById("fullname").focus();
		return false;
	}
	else if(trim(document.getElementById("mwcid").value)=="")
	{
		alertify.alert("Please enter Mahindra world city identification card number!");
		document.getElementById("mwcid").focus();
		return false;
	}
	else if(trim(document.getElementById("dlno").value)=="")
	{
		alertify.alert("Please enter driving licence number!");
		document.getElementById("dlno").focus();
		return false;
	}
	else if(trim(document.getElementById("contactno").value)=="")
	{
		alertify.alert("Please enter contact number!");
		document.getElementById("contactno").focus();
		return false;
	}
	else if(trim(document.getElementById("address").value)=="")
	{
		alertify.alert("Please enter address!");
		document.getElementById("address").focus();
		return false;
	}
	else if(trim(document.getElementById("area").value)=="")
	{
		alertify.alert("Please enter area!");
		document.getElementById("area").focus();
		return false;
	}
	else if(trim(document.getElementById("city").value)=="")
	{
		alertify.alert("Please enter city!");
		document.getElementById("city").focus();
		return false;
	}
	else if(trim(document.getElementById("state").value)=="")
	{
		alertify.alert("Please enter state!");
		document.getElementById("state").focus();
		return false;
	}
}

// validation function for profile page
function valideditagent_profile()
{
	
	if(trim(document.getElementById("name").value)=="")
	{
		alertify.alert("Name field required!");
		document.getElementById("name").focus();
		return false;
	}
	else if(trim(document.getElementById("gender").value)=="")
	{
		alertify.alert("Gender field required!");
		document.getElementById("gender").focus();
		return false;
	}
	else if(trim(document.getElementById("dob").value)=="")
	{
		alertify.alert("Date of birth field required!");
		document.getElementById("dob").focus();
		return false;
	}
	else if(trim(document.getElementById("gender").value)=="")
	{
		alertify.alert("Gender field required!");
		document.getElementById("gender").focus();
		return false;
	}
	else if(trim(document.getElementById("email_id").value)=="")
	{
		alertify.alert("Email field required!");
		document.getElementById("email_id").focus();
		return false;
	}
	else if(trim(document.getElementById("contact_number").value)=="")
	{
		alertify.alert("Contact Number field required!");
		document.getElementById("contact_number").focus();
		return false;
	}
	else if(trim(document.getElementById("current_address").value)=="")
	{
		alertify.alert("Current Address field required!");
		document.getElementById("current_address").focus();
		return false;
	}
	else if(trim(document.getElementById("current_city").value)=="")
	{
		alertify.alert("Current City field required!");
		document.getElementById("current_city").focus();
		return false;
	}
	else if(trim(document.getElementById("current_state").value)=="")
	{
		alertify.alert("Current State field required!");
		document.getElementById("current_state").focus();
		return false;
	}
}
function valid_pwd()
{
	if(document.getElementById("new_pass").value=="")
	{
		alertify.alert("Please enter new password");
		document.getElementById("new_pass").focus();
		return false;
	}
	else if(document.getElementById("new_pass").value.length<6)
	{
		alertify.alert("Password should be at least 6 characters long!");
		document.getElementById("new_pass").focus();
		return false;
	}
	else if(document.getElementById("confirm_pass").value=="")
	{
		alertify.alert("Please enter repeat password");
		document.getElementById("confirm_pass").focus();
		return false;
	}
	else if(document.getElementById("new_pass").value!=document.getElementById("confirm_pass").value)
	{
		alertify.alert("Seems like you have entered wrong password in repeat password field!");
		document.getElementById("confirm_pass").focus();
		return false;
	}
}

function validateaddeditpayband()
{
	if(trim(document.getElementById("band").value)=="")
	{
		alertify.alert("Please enter payband!");
		document.getElementById("band").focus();
		return false;
	}
}

function validateaddeditprocess()
{
	
	if(trim(document.getElementById("processname").value)=="")
	{
		alertify.alert("Please enter process name!");
		document.getElementById("processname").focus();
		return false;
	}
	
}
function validateaddeditservice()
{
	
	if(trim(document.getElementById("service").value)=="")
	{
		alertify.alert("Please enter vendor service name!");
		document.getElementById("service").focus();
		return false;
	}
	
}
function validateaddeditzones()
{
	
	if(trim(document.getElementById("zone_name").value)=="")
	{
		alertify.alert("Please enter zone name!");
		document.getElementById("zone_name").focus();
		return false;
	}
	
}
function validateaddeditdepartment()
{
	if(trim(document.getElementById("processid").value)=="0")
	{
		alertify.alert("Please select process of the department!");
		document.getElementById("processid").focus();
		return false;
	}
	else if(trim(document.getElementById("deptname").value)=="")
	{
		alertify.alert("Please enter department name!");
		document.getElementById("deptname").focus();
		return false;
	}
	
}

function validateaddeditdesignation()
{
	if(trim(document.getElementById("processid").value)=="0")
	{
		alertify.alert("Please select process!");
		document.getElementById("processid").focus();
		return false;
	}
	else if(trim(document.getElementById("deptid").value)=="")
	{
		alertify.alert("Please select department!");
		document.getElementById("deptid").focus();
		return false;
	}
	else if(trim(document.getElementById("designation").value)=="")
	{
		alertify.alert("Please enter designation name!");
		document.getElementById("designation").focus();
		return false;
	}
}

function validsettings()
{
	if(trim(document.getElementById("leave_per_month").value)=="")
	{
		alertify.alert("Please enter no of leaves per month an employee can take?");
		document.getElementById("leave_per_month").focus();
		return false;
	}
	else if(isNaN(trim(document.getElementById("leave_per_month").value)))
	{
		alertify.alert("Please enter numeric no of leaves per month an employee can take?");
		document.getElementById("leave_per_month").focus();
		return false;
	}
	else if(trim(document.getElementById("comp_off_expiry_days").value)=="")
	{
		alertify.alert("Please enter no of days after which comp off will be expired?");
		document.getElementById("comp_off_expiry_days").focus();
		return false;
	}
	else if(isNaN(trim(document.getElementById("comp_off_expiry_days").value)))
	{
		alertify.alert("Please enter numeric no of days after which comp off will be expired?");
		document.getElementById("comp_off_expiry_days").focus();
		return false;
	}
	else if(trim(document.getElementById("max_forward_leaves").value)=="")
	{
		alertify.alert("Please enter no of leaves that can be forwarded into next year?");
		document.getElementById("max_forward_leaves").focus();
		return false;
	}
	else if(isNaN(trim(document.getElementById("max_forward_leaves").value)))
	{
		alertify.alert("Please enter numeric no of leaves that can be forwarded into next year?");
		document.getElementById("max_forward_leaves").focus();
		return false;
	}
	else if(trim(document.getElementById("maternity_leaves").value)=="")
	{
		alertify.alert("Please enter no of leaves that are provided as maternity leaves?");
		document.getElementById("maternity_leaves").focus();
		return false;
	}
	else if(isNaN(trim(document.getElementById("maternity_leaves").value)))
	{
		alertify.alert("Please enter numeric no of leaves that are provided as maternity leaves");
		document.getElementById("maternity_leaves").focus();
		return false;
	}
	else if(trim(document.getElementById("paternity_leaves").value)=="")
	{
		alertify.alert("Please enter no of leaves that are provided as paternity leaves?");
		document.getElementById("paternity_leaves").focus();
		return false;
	}
	else if(isNaN(trim(document.getElementById("paternity_leaves").value)))
	{
		alertify.alert("Please enter numeric no of leaves that are provided as paternity leaves?");
		document.getElementById("paternity_leaves").focus();
		return false;
	}
	else if(trim(document.getElementById("max_normal_leaves").value)=="")
	{
		alertify.alert("Please enter maximum no of leaves that an employee can take at a time?");
		document.getElementById("max_normal_leaves").focus();
		return false;
	}
	else if(isNaN(trim(document.getElementById("max_normal_leaves").value)))
	{
		alertify.alert("Please enter numeric maximum no of leaves that an employee can take at a time?");
		document.getElementById("max_normal_leaves").focus();
		return false;
	}
	else if(trim(document.getElementById("max_sick_leaves").value)=="")
	{
		alertify.alert("Please enter maximum no of sick leaves that an employee can take at a time?");
		document.getElementById("max_sick_leaves").focus();
		return false;
	}
	else if(isNaN(trim(document.getElementById("max_sick_leaves").value)))
	{
		alertify.alert("Please enter numeric maximum no of sick leaves that an employee can take at a time?");
		document.getElementById("max_sick_leaves").focus();
		return false;
	}
	else if(trim(document.getElementById("max_comp_off").value)=="")
	{
		alertify.alert("Please enter maximum no of leaves that can be given to an employee as complementory off?");
		document.getElementById("max_comp_off").focus();
		return false;
	}
	else if(isNaN(trim(document.getElementById("max_comp_off").value)))
	{
		alertify.alert("Please enter numeric maximum no of leaves that can be given to an employee as complementory off?");
		document.getElementById("max_comp_off").focus();
		return false;
	}
    else
    {
        document.settingForm.submit();
    }
	
}